﻿package
{

	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import flash.text.*;
	import flash.media.*;
	import flash.display.MovieClip;
	import flash.utils.Timer;
	import flash.events.TimerEvent;



	public class lift extends MovieClip
	{
		var times:int;
		var vx:Number;
		var vy:Number;

		var currentlift_x:int = 0;
		var currentlift_y:int = 0;

		var floor1lift_x:int = 884;
		var floor1lift_y:int = 631;

		var floor2lift_x:int = 884;
		var floor2lift_y:int = 521;

		var floor3lift_x:int = 884;
		var floor3lift_y:int = 406;

		var floor4lift_x:int = 884;
		var floor4lift_y:int = 293;

		var floor5lift_x:int = 884;
		var floor5lift_y:int = 178;

		var floor6lift_x:int = 884;
		var floor6lift_y:int = 59;

		var timer_mypass:Timer = new Timer(2000,50);

		var img_mybg:img_background = new img_background();
		var btn_mystart:btn_start = new btn_start();
		var btn_mystop:btn_stop = new btn_stop();
		var img_mylift:img_lift = new img_lift();
		var img_myworking:img_working = new img_working();
		//----------------------------------testing
		var arr_passnum:Array=new Array();
		var arr_passcurrent:Array=new Array();
		var arr_passintent:Array=new Array();
		//----------------------------------testing
		var num_floor1_up:TextField=new TextField();
		var num_floor1_down:TextField=new TextField();

		var num_floor2_up:TextField=new TextField();
		var num_floor2_down:TextField=new TextField();

		var num_floor3_up:TextField=new TextField();
		var num_floor3_down:TextField=new TextField();

		var num_floor4_up:TextField=new TextField();
		var num_floor4_down:TextField=new TextField();

		var num_floor5_up:TextField=new TextField();
		var num_floor5_down:TextField=new TextField();

		var num_floor6_up:TextField=new TextField();
		var num_floor6_down:TextField=new TextField();

		//UI

		//var passengers:Array=new Array();

		var quantity_floor1_up:int = 0;
		var quantity_floor1_down:int = 0;

		var quantity_floor2_up:int = 0;
		var quantity_floor2_down:int = 0;

		var quantity_floor3_up:int = 0;
		var quantity_floor3_down:int = 0;

		var quantity_floor4_up:int = 0;
		var quantity_floor4_down:int = 0;

		var quantity_floor5_up:int = 0;
		var quantity_floor5_down:int = 0;

		var quantity_floor6_up:int = 0;
		var quantity_floor6_down:int = 0;

		var quantity_all:int = 0;

		public function lift()
		{



			//add background
			img_mybg.x = 0;
			img_mybg.y = 0;

			//add start and stop button
			btn_mystart.x = 315;
			btn_mystart.y = 26;
			btn_mystart.addEventListener(MouseEvent.CLICK, MyStart);

			btn_mystop.x = 315;
			btn_mystop.y = 95;

			img_mylift.x = 884;
			img_mylift.y = 631;

			img_myworking.x = 354;
			img_myworking.y = 306;

			addChild(img_mybg);
			addChild(btn_mystart);
			addChild(btn_mystop);
		}
		public function MyStart(event:MouseEvent):void
		{
			addChild(img_mylift);
			addChild(img_myworking);


			timer_mypass.addEventListener("timer", GeneratePass);
			timer_mypass.start();


		}
		//public function GeneratePass():void
		function GeneratePass(event:TimerEvent):void
		{

			//-----------------------------1 text
			num_floor1_up.x = 220;
			num_floor1_up.y = 444;
			num_floor1_up.textColor = 0x00FF00;

			num_floor1_down.x = 363;
			num_floor1_down.y = 444;
			num_floor1_down.textColor = 0x00FF00;

			//-----------------------------2 text
			num_floor2_up.x = 220;
			num_floor2_up.y = 495;
			num_floor2_up.textColor = 0x00FF00;

			num_floor2_down.x = 363;
			num_floor2_down.y = 495;
			num_floor2_down.textColor = 0x00FF00;

			//-----------------------------3 text
			num_floor3_up.x = 220;
			num_floor3_up.y = 541;
			num_floor3_up.textColor = 0x00FF00;

			num_floor3_down.x = 363;
			num_floor3_down.y = 541;
			num_floor3_down.textColor = 0x00FF00;

			//-----------------------------4 text
			num_floor4_up.x = 220;
			num_floor4_up.y = 591;
			num_floor4_up.textColor = 0x00FF00;

			num_floor4_down.x = 363;
			num_floor4_down.y = 591;
			num_floor4_down.textColor = 0x00FF00;

			//-----------------------------5 text
			num_floor5_up.x = 220;
			num_floor5_up.y = 638;
			num_floor5_up.textColor = 0x00FF00;

			num_floor5_down.x = 363;
			num_floor5_down.y = 638;
			num_floor5_down.textColor = 0x00FF00;

			//-----------------------------6 text
			num_floor6_up.x = 220;
			num_floor6_up.y = 686;
			num_floor6_up.textColor = 0x00FF00;

			num_floor6_down.x = 363;
			num_floor6_down.y = 686;
			num_floor6_down.textColor = 0x00FF00;
			//num_floor1_up.text = quantity_floor1.toString();
			//addChild(num_floor1_up);


			//===================================================================================================================
			var arr_passnum:Array=new Array();
			var arr_passcurrent:Array=new Array();
			var arr_passintent:Array=new Array();



			var rand:int = Math.round(Math.random()*(6-1))+1;
			trace("current floor is: "+rand);


			quantity_all = quantity_all + 1;
			trace("total quantity is: "+quantity_all);
			//-------------------testing
			var intentrand:int = Math.round(Math.random()*(6-1))+1;
			trace("intent floor is: "+intentrand);
			arr_passnum[quantity_all] = quantity_all;
			arr_passcurrent[quantity_all] = rand;
			arr_passintent[quantity_all] = intentrand;
			//-------------------testing

			//var passengers[quantity_all]:img_passenger = new img_passenger();
			//var passengers:img_passenger = new img_passenger();//2011.8.19


			//test------------------------
			//var upordown:int = Math.round(Math.random()*(1-0))+0;
			//trace("up or down is: "+upordown);

			//test------------------------
			//=============================generatepassengers(rand,intentrand);


			if (rand == 1)
			{
				
//				if (intentrand == 1)
//				{
//					var passengers11:one_1 = new one_1();
//					passengers11.x = 772-(quantity_floor1_up+quantity_floor1_down)*40;
//					passengers11.y = 640;
//					addChild(passengers11);
//				}
				if (intentrand==2)
				{
					var passengers12:one_2 = new one_2();
					passengers12.x = 772-(quantity_floor1_up+quantity_floor1_down)*40;
					passengers12.y = 640;
					addChild(passengers12);
				}
				else if (intentrand==3)
				{
					var passengers13:one_3 = new one_3();
					passengers13.x = 772-(quantity_floor1_up+quantity_floor1_down)*40;
					passengers13.y = 640;
					addChild(passengers13);
				}
				else if (intentrand==4)
				{
					var passengers14:one_4 = new one_4();
					passengers14.x = 772-(quantity_floor1_up+quantity_floor1_down)*40;
					passengers14.y = 640;
					addChild(passengers14);
				}
				else if (intentrand==5)
				{
					var passengers15:one_5 = new one_5();
					passengers15.x = 772-(quantity_floor1_up+quantity_floor1_down)*40;
					passengers15.y = 640;
					addChild(passengers15);
				}
				else if (intentrand==6)
				{
					var passengers16:one_6 = new one_6();
					passengers16.x = 772-(quantity_floor1_up+quantity_floor1_down)*40;
					passengers16.y = 640;
					addChild(passengers16);
				}
				//---------------------------------------------------------------------
				
		
				if ((intentrand-rand)>=0&&intentrand!=1)
				{
					quantity_floor1_up++;
				}
				else if ((intentrand-rand)<=0&&intentrand!=1)
				{
					quantity_floor1_down++;
				}
			}
			
			else if (rand==2)
			{if (intentrand == 1)
				{
					var passengers21:two_1 = new two_1();
					passengers21.x = 772-(quantity_floor2_up+quantity_floor2_down)*40;
					passengers21.y = 533;
					addChild(passengers21);
				}
//				else if (intentrand==2)
//				{
//					var passengers22:two_2 = new two_2();
//					passengers22.x = 772-(quantity_floor2_up+quantity_floor2_down)*40;
//					passengers22.y = 533;
//					addChild(passengers12);
//				}
				else if (intentrand==3)
				{
					var passengers23:two_3 = new two_3();
					passengers23.x = 772-(quantity_floor2_up+quantity_floor2_down)*40;
					passengers23.y = 533;
					addChild(passengers23);
				}
				else if (intentrand==4)
				{
					var passengers24:two_4 = new two_4();
					passengers24.x = 772-(quantity_floor2_up+quantity_floor2_down)*40;
					passengers24.y = 533;
					addChild(passengers24);
				}
				else if (intentrand==5)
				{
					var passengers25:two_5 = new two_5();
					passengers25.x = 772-(quantity_floor2_up+quantity_floor2_down)*40;
					passengers25.y = 533;
					addChild(passengers25);
				}
				else if (intentrand==6)
				{
					var passengers26:two_6 = new two_6();
					passengers26.x = 772-(quantity_floor2_up+quantity_floor2_down)*40;
					passengers26.y = 533;
					addChild(passengers26);
				}
				//======================================================================================
				//passengers.x = 772-(quantity_floor2_up+quantity_floor2_down)*40;
//				passengers.y = 533;
//				addChild(passengers);
				if ((intentrand-rand)>=0&&intentrand!=2)
				{
					quantity_floor2_up++;
				}
				else if ((intentrand-rand)<=0&&intentrand!=2)
				{
					quantity_floor2_down++;
				}

			}
			else if (rand==3)
			{
				if (intentrand == 1)
				{
					var passengers31:three_1 = new three_1();
					passengers31.x = 772-(quantity_floor3_up+quantity_floor3_down)*40;
					passengers31.y = 415;
					addChild(passengers31);
				}
				else if (intentrand==2)
				{
					var passengers32:three_2 = new three_2();
					passengers32.x = 772-(quantity_floor3_up+quantity_floor3_down)*40;
					passengers32.y = 415;
					addChild(passengers32);
				}
//				else if (intentrand==3)
//				{
//					var passengers33:three_3 = new three_3();
//					passengers33.x = 772-(quantity_floor3_up+quantity_floor3_down)*40;
//					passengers33.y = 415;
//					addChild(passengers33);
//				}
				else if (intentrand==4)
				{
					var passengers34:three_4 = new three_4();
					passengers34.x = 772-(quantity_floor3_up+quantity_floor3_down)*40;
					passengers34.y = 415;
					addChild(passengers34);
				}
				else if (intentrand==5)
				{
					var passengers35:three_5 = new three_5();
					passengers35.x = 772-(quantity_floor3_up+quantity_floor3_down)*40;
					passengers35.y = 415;
					addChild(passengers35);
				}
				else if (intentrand==6)
				{
					var passengers36:three_6 = new three_6();
					passengers36.x = 772-(quantity_floor3_up+quantity_floor3_down)*40;
					passengers36.y = 415;
					addChild(passengers36);
				}
				
				
				
//				passengers.x = 772-(quantity_floor3_up+quantity_floor3_down)*40;
//				passengers.y = 415;
//				addChild(passengers);
				if ((intentrand-rand)>=0&&intentrand!=3)
				{
					quantity_floor3_up++;
				}
				else if ((intentrand-rand)<=0&&intentrand!=3)
				{
					quantity_floor3_down++;
				}
			}
			else if (rand==4)
			{
				if (intentrand == 1)
				{
					var passengers41:four_1 = new four_1();
					passengers41.x = 772-(quantity_floor4_up+quantity_floor4_down)*40;
					passengers41.y = 305;
					addChild(passengers41);
				}
				else if (intentrand==2)
				{
					var passengers42:four_2 = new four_2();
					passengers42.x = 772-(quantity_floor4_up+quantity_floor4_down)*40;
					passengers42.y = 305;
					addChild(passengers42);
				}
				else if (intentrand==3)
				{
					var passengers43:four_3 = new four_3();
					passengers43.x = 772-(quantity_floor4_up+quantity_floor4_down)*40;
					passengers43.y = 305;
					addChild(passengers43);
				}
//				else if (intentrand==4)
//				{
//					var passengers44:four_4 = new four_4();
//					passengers44.x = 772-(quantity_floor4_up+quantity_floor4_down)*40;
//					passengers44.y = 305;
//					addChild(passengers44);
//				}
				else if (intentrand==5)
				{
					var passengers45:four_5 = new four_5();
					passengers45.x = 772-(quantity_floor4_up+quantity_floor4_down)*40;
					passengers45.y = 305;
					addChild(passengers45);
				}
				else if (intentrand==6)
				{
					var passengers46:four_6 = new four_6();
					passengers46.x = 772-(quantity_floor4_up+quantity_floor4_down)*40;
					passengers46.y = 305;
					addChild(passengers46);
				}
				
//				passengers.x = 772-(quantity_floor4_up+quantity_floor4_down)*40;
//				passengers.y = 305;
//				addChild(passengers);
				if ((intentrand-rand)>=0&&intentrand!=4)
				{
					quantity_floor4_up++;
				}
				else if ((intentrand-rand)<=0&&intentrand!=4)
				{
					quantity_floor4_down++;
				}
			}
			else if (rand==5)
			{
				if (intentrand == 1)
				{
					var passengers51:five_1 = new five_1();
					passengers51.x = 772-(quantity_floor5_up+quantity_floor5_down)*40;
					passengers51.y = 187;
					addChild(passengers51);
				}
				else if (intentrand==2)
				{
					var passengers52:five_2 = new five_2();
					passengers52.x = 772-(quantity_floor5_up+quantity_floor5_down)*40;
					passengers52.y = 187;
					addChild(passengers52);
				}
				else if (intentrand==3)
				{
					var passengers53:five_3 = new five_3();
					passengers53.x = 772-(quantity_floor5_up+quantity_floor5_down)*40;
					passengers53.y = 187;
					addChild(passengers53);
				}
				else if (intentrand==4)
				{
					var passengers54:five_4 = new five_4();
					passengers54.x = 772-(quantity_floor5_up+quantity_floor5_down)*40;
					passengers54.y = 187;
					addChild(passengers54);
				}
//				else if (intentrand==5)
//				{
//					var passengers55:five_5 = new five_5();
//					passengers55.x = 772-(quantity_floor5_up+quantity_floor5_down)*40;
//					passengers55.y = 187;
//					addChild(passengers55);
//				}
				else if (intentrand==6)
				{
					var passengers56:five_6 = new five_6();
					passengers56.x = 772-(quantity_floor5_up+quantity_floor5_down)*40;
					passengers56.y = 187;
					addChild(passengers56);
				}
				
				
//				passengers.x = 772-(quantity_floor5_up+quantity_floor5_down)*40;
//				passengers.y = 187;
//				addChild(passengers);
				if ((intentrand-rand)>=0&&intentrand!=5)
				{
					quantity_floor5_up++;
				}
				else if ((intentrand-rand)<=0&&intentrand!=5)
				{
					quantity_floor5_down++;
				}
			}
			else if (rand==6)
			{
				
				if (intentrand == 1)
				{
					var passengers61:six_1 = new six_1();
					passengers61.x = 772-(quantity_floor6_up+quantity_floor6_down)*40;
					passengers61.y = 70;
					addChild(passengers61);
				}
				else if (intentrand==2)
				{
					var passengers62:six_2 = new six_2();
					passengers62.x = 772-(quantity_floor6_up+quantity_floor6_down)*40;
					passengers62.y = 70;
					addChild(passengers62);
				}
				else if (intentrand==3)
				{
					var passengers63:six_3 = new six_3();
					passengers63.x = 772-(quantity_floor6_up+quantity_floor6_down)*40;
					passengers63.y = 70;
					addChild(passengers63);
				}
				else if (intentrand==4)
				{
					var passengers64:six_4 = new six_4();
					passengers64.x = 772-(quantity_floor6_up+quantity_floor6_down)*40;
					passengers64.y = 70;
					addChild(passengers64);
				}
				else if (intentrand==5)
				{
					var passengers65:six_5 = new six_5();
					passengers65.x = 772-(quantity_floor6_up+quantity_floor6_down)*40;
					passengers65.y = 70;
					addChild(passengers65);
				}
//				else if (intentrand==6)
//				{
//					var passengers66:six_6 = new six_6();
//					passengers66.x = 772-(quantity_floor6_up+quantity_floor6_down)*40;
//					passengers66.y = 70;
//					addChild(passengers66);
//				}
				
//				passengers.x = 772-(quantity_floor6_up+quantity_floor6_down)*40;
//				passengers.y = 70;
//				addChild(passengers);
				if ((intentrand-rand)>=0&&intentrand!=6)
				{
					quantity_floor6_up++;
				}
				else if ((intentrand-rand)<=0&&intentrand!=6)
				{
					quantity_floor6_down++;
				}
			}
			
			
			num_floor1_up.text = quantity_floor1_up.toString();
			addChild(num_floor1_up);
			num_floor1_down.text = quantity_floor1_down.toString();
			addChild(num_floor1_down);

			num_floor2_up.text = quantity_floor2_up.toString();
			addChild(num_floor2_up);
			num_floor2_down.text = quantity_floor2_down.toString();
			addChild(num_floor2_down);

			num_floor3_up.text = quantity_floor3_up.toString();
			addChild(num_floor3_up);
			num_floor3_down.text = quantity_floor3_down.toString();
			addChild(num_floor3_down);

			num_floor4_up.text = quantity_floor4_up.toString();
			addChild(num_floor4_up);
			num_floor4_down.text = quantity_floor4_down.toString();
			addChild(num_floor4_down);

			num_floor5_up.text = quantity_floor5_up.toString();
			addChild(num_floor5_up);
			num_floor5_down.text = quantity_floor5_down.toString();
			addChild(num_floor5_down);

			num_floor6_up.text = quantity_floor6_up.toString();
			addChild(num_floor6_up);
			num_floor6_down.text = quantity_floor6_down.toString();
			addChild(num_floor6_down);



		}
		
		/*
		
		public function generatepassengers(currentFloor:int, purposeFloor:int):void
		{
			if (currentFloor == 1)
			{
				if (purposeFloor == 1)
				{
					var passengers:one_1 = new one_1();
				}
				else if (purposeFloor==2)
				{
					var passengers:one_2 = new one_2();
				}
				else if (purposeFloor==3)
				{
					var passengers:one_3 = new one_3();
				}
				else if (purposeFloor==4)
				{
					var passengers:one_4 = new one_4();
				}
				else if (purposeFloor==5)
				{
					var passengers:one_5 = new one_5();
				}
				else if (purposeFloor==6)
				{
					var passengers:one_6 = new one_6();
				}
			}
			else if (currentFloor==2)
			{
				if (purposeFloor == 1)
				{
					var passengers:two_1 = new two_1();
				}
				else if (purposeFloor==2)
				{
					var passengers:two_2 = new two_2();
				}
				else if (purposeFloor==3)
				{
					var passengers:two_3 = new two_3();
				}
				else if (purposeFloor==4)
				{
					var passengers:two_4 = new two_4();
				}
				else if (purposeFloor==5)
				{
					var passengers:two_5 = new two_5();
				}
				else if (purposeFloor==6)
				{
					var passengers:two_6 = new two_6();
				}
			}
			else if (currentFloor==3)
			{
				if (purposeFloor == 1)
				{
					var passengers:three_1 = new three_1();
				}
				else if (purposeFloor==2)
				{
					var passengers:three_2 = new three_2();
				}
				else if (purposeFloor==3)
				{
					var passengers:three_3 = new three_3();
				}
				else if (purposeFloor==4)
				{
					var passengers:three_4 = new three_4();
				}
				else if (purposeFloor==5)
				{
					var passengers:three_5 = new three_5();
				}
				else if (purposeFloor==6)
				{
					var passengers:three_6 = new three_6();
				}
			}
			else if (currentFloor==4)
			{
				if (purposeFloor == 1)
				{
					var passengers:four_1 = new four_1();
				}
				else if (purposeFloor==2)
				{
					var passengers:four_2 = new four_2();
				}
				else if (purposeFloor==3)
				{
					var passengers:four_3 = new four_3();
				}
				else if (purposeFloor==4)
				{
					var passengers:four_4 = new four_4();
				}
				else if (purposeFloor==5)
				{
					var passengers:four_5 = new four_5();
				}
				else if (purposeFloor==6)
				{
					var passengers:four_6 = new four_6();
				}


			}
			else if (currentFloor==5)
			{
				if (purposeFloor == 1)
				{
					var passengers:five_1 = new five_1();
				}
				else if (purposeFloor==2)
				{
					var passengers:five_2 = new five_2();
				}
				else if (purposeFloor==3)
				{
					var passengers:five_3 = new five_3();
				}
				else if (purposeFloor==4)
				{
					var passengers:five_4 = new five_4();
				}
				else if (purposeFloor==5)
				{
					var passengers:five_5 = new five_5();
				}
				else if (purposeFloor==6)
				{
					var passengers:five_6 = new five_6();
				}
			}
			else if (currentFloor==6)
			{
				if (purposeFloor == 1)
				{
					var passengers:six_1 = new six_1();
				}
				else if (purposeFloor==2)
				{
					var passengers:six_2 = new six_2();
				}
				else if (purposeFloor==3)
				{
					var passengers:six_3 = new six_3();
				}
				else if (purposeFloor==4)
				{
					var passengers:six_4 = new six_4();
				}
				else if (purposeFloor==5)
				{
					var passengers:six_5 = new six_5();
				}
				else if (purposeFloor==6)
				{
					var passengers:six_6 = new six_6();
				}

			}

		}

		*/

		public function liftmove():void
		{
			times = 10;
			var current_lift_floor1_x = 884;
			var current_lift_floor1_y = 631;

			var current_lift_floor6_x = 884;
			var current_lift_floor6_y = 59;

			vx = (current_lift_floor6_x-current_lift_floor1_x)/times;
			vy = (current_lift_floor6_y-current_lift_floor1_y)/times;
			img_mylift.addEventListener(Event.ENTER_FRAME,move1);
			function move1(e:Event):void
			{
				img_mylift.x +=  vx;
				img_mylift.y +=  vy;
				times--;
				if (times == 0)
				{
					img_mylift.removeEventListener(Event.ENTER_FRAME,move1);
					times = 10;

				}
			}

		}

	}

}